from VizSpread.appengine.contactsloader import ContactsLoader
from VizSpread.appengine.models import Dataset, Contact

from VizSpread.tests import testdata

from google.appengine.api.users import User

class TestContactsLoader():
	def setup(self):
		self.defaultData=testdata.DEFAULT_DATA
		self.dataSetName = "Test"
		self.dataCentre = "14 Bond Street, London, UK"
		self.user = User("test3@foo.com")

	def test_load_dataset(self):
		dataset = Dataset(name=self.dataSetName, owner=self.user)
		dataset.put()
		
		contact_address1 = "23 New Church Road, Brighton, East Sussex, UK"
		contact1 = Contact(set=dataset, address=contact_address1)
		contact1.put()

		contact_address2 = "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA"
		contact2 = Contact(set=dataset, address=contact_address2)
		contact2.put()
		
		loader = ContactsLoader(self.dataSetName)
		loadSuccess = loader.loadDataset(self.user)
		
		assert loadSuccess
		

